package com.david.config;

import com.david.vo.ResponseBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 捕获全局异常处理
 * @create: 2021-05-03-16-53
 * @author: David
 **/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = MyException.class)
    @ResponseBody
    public ResponseBean myExceptionHandler(MyException e){
        return ResponseBean.error(e.getMessage(), 400);
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResponseBean tokenExceptionHandler(Exception e){
        log.info("异常" + e.getMessage());
        return ResponseBean.error("登录状态异常！", 200);
    }
}
